{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ba05d40c",
   "metadata": {},
   "source": [
    "### 条件判断"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc9154ed",
   "metadata": {},
   "source": [
    "if, else , elif等常规判断，语法和C基本一致，不再复述"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "310907e0",
   "metadata": {},
   "source": [
    "#### 再议input"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efa0559d",
   "metadata": {},
   "source": [
    "input返回的数据类型是str，str不能直接和整数比较，必须先把str转换成整数，即调用int()函数来完成"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e0915e0d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "birth:1982\n",
      "00前\n"
     ]
    }
   ],
   "source": [
    "s = input('birth:')\n",
    "birth = int(s)\n",
    "if birth < 2000:\n",
    "    print('00前')\n",
    "else:\n",
    "    print('00后')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c60757fc",
   "metadata": {},
   "source": [
    "#### 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "25c91fab",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "过重\n"
     ]
    }
   ],
   "source": [
    "height = 1.75\n",
    "weight = 85\n",
    "bmi = weight / height ** 2\n",
    "if bmi < 18.5:\n",
    "    print('过轻')\n",
    "elif bmi < 25:\n",
    "    print('正常')\n",
    "elif bmi < 28:\n",
    "    print('过重')\n",
    "elif bmi < 32:\n",
    "    print('肥胖')\n",
    "else:\n",
    "    print('严重肥胖')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42208b9b",
   "metadata": {},
   "source": [
    "### 小结"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "902626c7",
   "metadata": {},
   "source": [
    "条件判断从下向上匹配，当满足条件时执行对应的块内语句，后续的elif和else都不再执行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58c20927",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
